﻿using DesignPatterns.Factory.ImpService;
using DesignPatterns.Factory.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DesignPatterns.Factory
{
    public  class FactoryPrintService
    {
        public void Print() {

            // 简单工厂：减少业务类和构建的耦合性,但是不符合开闭设计原则(添加新的水果品种需要修改代码)和职责单一原则(任何一个水果品种构造函数发生变更，都要调整里面的逻辑，所以和一个类的修改只能有一个原因相悖)；
            Console.WriteLine("---------------简单模式---------------");
            var apple = SimpleFactory.CreateFruit("apple");
            apple.Show();
            var orange = SimpleFactory.CreateFruit("orange");
            orange.Show();

            // 工厂模式：很好的满足了开闭原则和职责单一原则，但无法解决产品簇的问题(只能生产一种产品，无法生产多种有关联的产品)；
            Console.WriteLine("---------------工厂模式---------------");
            IFruitFactory appleFactory = new AppleFactory();
            var apple1 =  appleFactory.CreateFruit();
            apple1.Show();

            IFruitFactory orangeFactory = new OrangeFactory();
            var org1 = orangeFactory.CreateFruit();
            org1.Show();

            // 抽象工厂模式：
            Console.WriteLine("---------------抽象工厂模式---------------");
            IFruitShopFactory shop = new BaseShopFactory();
            var app2 = shop.CreateApple();
            var org2 = shop.CreateOrange();
            app2.Show();
            org2.Show();

            IFruitShopFactory goodShop = new HightShopFactory();
            var app3 = goodShop.CreateApple();
            var org3 = goodShop.CreateOrange();
            app3.Show();
            org3.Show();
        }
    }
}
